package cn.cocho.android.mc.comp.dialog;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager.LayoutParams;
import android.widget.TextView;

import cn.cocho.android.mc.R;
import cn.cocho.android.mc.comp.button.McButton;
import cn.cocho.android.mc.storage.ApplicationCache;

/**
 * 自定义对话框
 * 
 * @author HAIKANG SONG
 * @2013年11月12日 @上午11:08:45
 */
public class ProgressDialog extends AlertDialog {
	
	TextView titleView;
	TextView contentView;
	McButton cancelButton;
	View view;

	public ProgressDialog() {
		super(ApplicationCache.context);
		initWidget(ApplicationCache.context);
		initCancelBtn();
	}
	
	public ProgressDialog(CharSequence title, CharSequence message) {
		super(ApplicationCache.context);
		initWidget(ApplicationCache.context);
		initCancelBtn();
		setTitle(title);
		setMessage(message);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(view);
	}

	private void initWidget(Context context) {
		LayoutInflater inflater = LayoutInflater.from(context);
		view = inflater.inflate(R.layout.progress_dialog, null);
		titleView = (TextView) view.findViewById(R.id.progress_dialog_title);
		contentView = (TextView) view.findViewById(R.id.progress_dialog_content);
		cancelButton = (McButton) view.findViewById(R.id.progress_dialog_cancel_btn);
	}

	public void setTitle(CharSequence title) {
		titleView.setText(title);
	}

	public void setMessage(CharSequence message) {
		contentView.setText(message);
	}

	@Override
	public void onWindowAttributesChanged(LayoutParams params) {
		super.onWindowAttributesChanged(params);
	}

	public void initCancelBtn(){
		cancelButton.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				dismiss();
			}
		});
	}

	public McButton getCancelButton() {
		return cancelButton;
	}

	public void setCancelButton(McButton cancelButton) {
		this.cancelButton = cancelButton;
	}
	
	
	
	
}
